package com.real.fact.web.product.application;

import com.globant.katari.core.application.Command;
import com.real.fact.web.product.domain.Product;
import com.real.fact.web.product.domain.ProductRepository;

/**
 * @since Jul 3, 2011
 */
public class DeleteProductCommand implements Command<Void> {

  private final ProductRepository productRepository;
  private long productId;

  public DeleteProductCommand(final ProductRepository productRepository) {
    this.productRepository = productRepository;
  }

  public Void execute() {
    Product product = productRepository.findById(productId);
    if (product.isActive())
      product.setInactive();
    else
      product.setActive();
    productRepository.save(product);
    return null;
  }

  public long getProductId() {
    return productId;
  }

  public void setProductId(long productId) {
    this.productId = productId;
  }

}
